package ch.unifr.diva.multimodals.spherex;

import android.os.Vibrator;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

	public class MyOnSeekBarChangeListener implements OnSeekBarChangeListener{
		private String name;
    	private NetConfigurationActivity netConfig;
		private Vibrator vibrator;
		private MultimodalDialog md;
		
    	/**
    	 * Constructor
    	 * @param name The bar name
    	 * @param netConfig
    	 */
		public MyOnSeekBarChangeListener(String name, NetConfigurationActivity netConfig){
		super();
		this.name=name;
		this.netConfig=netConfig;
		this.md=new MultimodalDialog(netConfig);
		}
		
    	@Override
    	public void onProgressChanged(SeekBar seekBar, int progress,
    	  boolean fromUser) {
    		//Better use the OnStopTrackingTouch event, as the receiver only accepts inputs each 1000 ms?
    		
//    		int progress=seekBar.getProgress();
//    		float progressConverted=0;
//    		//Convert the values, as Android does not support negative values in seekbars
//    		if(name.equals("Gravity"))
//    			progressConverted=((float)progress-1000)/100;
//    		if(name.equals("Friction"))
//    			progressConverted=((float)progress-2)/100;
//    		if(name.equals("Bounce"))
//    			progressConverted=((float)progress-2)/100;
//    		//Send the new value over the stream (separated method)
//    		netConfig.sendNewValue(name, progressConverted);
    	}
    	@Override
    	public void onStartTrackingTouch(SeekBar seekBar) {
    	}

    	@Override
    	public void onStopTrackingTouch(SeekBar seekBar) {
    		float progressConverted=0;
    		int progress=seekBar.getProgress();
    		//Convert the values, as Android does not support negative values in seekbars
    		if(name.equals("Gravity")){
    			progressConverted=((float)progress-1000)/100;
    			((TextView)netConfig.findViewById(R.id.gravityBarValue)).setText(Float.toString(progressConverted));
    		}
    		if(name.equals("Friction")){
    			progressConverted=((float)progress-2)/100;
    			((TextView)netConfig.findViewById(R.id.frictionBarValue)).setText(Float.toString(progressConverted));
    	}
    		if(name.equals("Bounce")){
    			progressConverted=((float)progress-2)/100;
    			((TextView)netConfig.findViewById(R.id.bounceBarValue)).setText(Float.toString(progressConverted));
	}
    		//Send the new value over the stream (separated method)
    		netConfig.sendNewValue(name, progressConverted);
    		//Repeat data transmission to loose less information
//    		onProgressChanged(seekBar, seekBar.getProgress(), true);
    		//Confirmation done in sendNewValue() method
    	}
    	
    	
    	
    	
    	
	
}

